package cn.lbwfree.day3_22;

import java.util.Arrays;
import java.util.Scanner;


/**
 * @date:2020年3月22日
 * @author:lbwfree
 * @number:BASIC-28
 */

// Huffuman Tree 
public class HuffumanTree {
	public static void main(String[] args) {
		Scanner inScanner = new Scanner(System.in);
		int num = inScanner.nextInt();
		if(num>100)
			return;
		int[] arrays = new int[num];
		int[] temp = new int[num];
		for (int i = 0; i < arrays.length; i++) {
			arrays[i]=inScanner.nextInt();
			if (arrays[i]>1000) {
				i--;
			}
		}
		
		for (int i = 0; i < arrays.length-1; i++) {
			Arrays.sort(arrays);
			temp[i]=arrays[0]+arrays[1];
			arrays[0]=temp[i];
			arrays[1]=Integer.MAX_VALUE;
		}
		int k=0;
		for (int i = 0; i < temp.length; i++) {
			k += temp[i];
		}
		System.out.println(k);
	}
//	private static int[] sort(int[] arrays) {
//		int[] temp = new int[arrays.length];
//		for
//		
//		
//		return arrays;
//	}
}
